#!/usr/bin/env pwsh
# 兼容双参数 / 单参数两种调用方式
param(
    [Parameter(Position = 0, Mandatory = $true)]
    [string]$Arg1,

    [Parameter(Position = 1, ValueFromRemainingArguments = $true)]
    [string[]]$Rest
)

# 判断模式
if ($Rest.Count -ge 1) {
    # 双参数模式：todo project xxxx ...
    $Project = $Arg1
    $Text    = $Rest -join ' '
}
else {
    # 单参数模式：todo xxx ...
    $Project = Split-Path -Leaf $PWD.Path   # 当前文件夹名
    $Text    = $Arg1
}

if ( [string]::IsNullOrWhiteSpace($Text) ) {
    Write-Host "Usage:"
    Write-Host "  Double parameter  .\todo.ps1 <Project> <Content...>"
    Write-Host "  Single parameter  .\todo.ps1 <Content...>          (Project=Current Folder Name)"
    exit 1
}
& bun run $PSScriptRoot\cli.ts create "$Project" "$Text"
